/********************************
 * ETK - Easy ToolKit
 * Copyright (C) 2007-2008 Ekinoks (scv.ekinoks@gmail.com)
 * All rights reserved.
 *
 *    This file is part of ETK.
 *
 *    Foobar is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    Foobar is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with Foobar; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ***********************************************************************************/

#ifndef __ETK_SHUTTERBUTTONMODEL_H__
#define __ETK_SHUTTERBUTTONMODEL_H__

#include <cassert>
#include <iostream>

#include "../../CallBack/LIST_EVENT.H"

namespace etk
{
    class ShutterButton;

    class ShutterButtonModel
    {
        public :

            ShutterButtonModel operator|| (const ShutterButtonModel & sb) const
            {
                ShutterButtonModel tmp(button_ | sb.button_, eventType_ | sb.eventType_);
                return tmp;
            }

            //bool testEventType( eventType_e eventType )
            bool operator== (const ShutterButton& shutterButton) const;
            bool operator!= (const ShutterButton& shutterButton) const;

            bool operator== (const ShutterButtonModel& shutterButtonModel) const;
            bool operator!= (const ShutterButtonModel& shutterButtonModel) const;


            bool isPressEvent() const
            {
                if(this->eventType_ == 0)
                    return true;
                return eventType_ != (1 << 3);
            }

            bool isReleaseEvent() const
            {
                if(this->eventType_ == 0)
                    return true;
                return eventType_ >= (1 << 3);
            }


            static const ShutterButtonModel BUTTON1;
            static const ShutterButtonModel BUTTON2;
            static const ShutterButtonModel BUTTON3;
            static const ShutterButtonModel BUTTON4;
            static const ShutterButtonModel BUTTON5;

            static const ShutterButtonModel CLICK;
            static const ShutterButtonModel DOUBLE_CLICK;
            static const ShutterButtonModel TRIPLE_CLICK;
            static const ShutterButtonModel RELEASE;

            static const ShutterButtonModel ANY;

        protected :

            ShutterButtonModel (int b, int et) : button_(b), eventType_(et)
            {

            }

            int getButton() const
            {
                return button_;
            }

            int getEventType() const
            {
                return eventType_;
            }

        private :

            friend class ToolKit;       // TODO : mettre juste pour ToolKit::setShutterButton

            inline static bool getBit(int v, int bit)
            {
                return v & (1 << bit);
            }

            /*
            ALL = 0
            BUTTON1 = 1 << 0
            BUTTON2 = 1 << 1
            BUTTON3 = 1 << 2
            BUTTON4 = 1 << 3
            BUTTON5 = 1 << 4
            */
            int button_;

            /*
            ALL = 0
            SIMPLE_CLICK = 1 << 0
            DOUBLE_CLICK = 1 << 1
            TRIPLE_CLICK = 1 << 2
            RELEASE = 1 << 3
            */
            int eventType_;
    };

}

#endif // __ETK_SHUTTERBUTTONMODEL_H__
